package com.ioc.pratise;

import com.ioc.pratise.controller.UserController;
import com.ioc.pratise.repository.UserRepository;
import com.ioc.pratise.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		//ApplicationContext表示Spring上下文，因为对象都交给Spring管理，所以获取对象要从Spring中获取
		ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
//		UserController bean = context.getBean(UserController.class);
//		bean.print();
//
//		UserController bean1 = context.getBean("userController", UserController.class);
//		bean1.print();
//
//		UserController bean2 = (UserController)context.getBean("userController");
//		bean2.print();
//
//		System.out.println(bean);
//		System.out.println(bean1);
//		System.out.println(bean2);

		UserService bean = context.getBean(UserService.class);
		bean.print();

		UserRepository bean1 = context.getBean(UserRepository.class);
		bean1.print();

	}

}
